package bid.yanhj.yanhaijiang.fragmentpageradapter;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

public class TextFragment extends Fragment {

    private TextView fragmentTv;

    public static TextFragment getTextFragment(String text) {
        Bundle bundle = new Bundle();
        bundle.putString("text", text);
        TextFragment textFragment = new TextFragment();
        textFragment.setArguments(bundle);
        return  textFragment;
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
//        return super.onCreateView(inflater, container, savedInstanceState);

        // 布局命名
        return inflater.inflate(R.layout.fragment_text, container, false);
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        fragmentTv = (TextView)view.findViewById(R.id.fragment_tv);

    }


    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        Bundle bundle = getArguments();
        String text = bundle.getString("text");
        fragmentTv.setText(text);
    }
}
